﻿
using System;
using System.Windows;
using System.Windows.Threading;
namespace WCYCReader.Utility
{
    public static class TimerHelper
    {
        public static void On(TimeSpan fromSeconds, Action action)
        {
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval=(fromSeconds);
            DispatcherTimer t = timer;
            t.Tick+=(delegate(object s, EventArgs args)
            {
                action();
                t.Stop();
            });
            t.Start();
        }

        public static void OnWithDispatcher(TimeSpan fromSeconds, Action action)
        {
            Deployment.Current.Dispatcher.BeginInvoke(delegate
            {
                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = (fromSeconds);
                DispatcherTimer t = timer;
                t.Tick += (delegate(object s, EventArgs args)
                {
                    action();
                    t.Stop();
                });
                t.Start();
            });
        }
    }
}

